/**
 * Copyright(C) 2019 FUYUN DATA SERVICES CO., LTD. - All Rights Reserved
 * Unauthorized copying of this file, via any medium is strictly prohibited
 * Proprietary and confidential
 */

import Cookies from "js-cookie";
import { decode } from "jsonwebtoken";
// 获取token 默认拿user_token的值

export function getTokenData(key?: string): object {
  let token = Cookies.get(key || "user_token");
  if (token && token.includes("bearer")) {
    token = token.split(" ")[1];
  }
  const data = decode(token ? token : "") || {};
  if (data && typeof data !== "string") {
    return data;
  }
  return {};
}
